package com.winsomely.leecode;

/**
 * Excel表列序号
 * 
 * @author liujiawei
 *
 */
public class TrailingZeroes {

	public int trailingZeroes1(int n) {
		java.math.BigInteger bigJi = java.math.BigInteger.ONE;
		for (long i = 2; i <= n; i++) {
			bigJi = bigJi.multiply(java.math.BigInteger.valueOf(i));
		}
		String s = bigJi.toString();
		System.out.println(s);
		int k = 0;
		for (int i = s.length() - 1; i >= 0; i--) {
			char c = s.charAt(i);
			if (c == '0') {
				k++;
			} else {
				break;
			}
		}
		return k;
	}

	public int trailingZeroes(int n) {
		int k = 0;
		for (int i = 5; i <= n; i += 5) {
			int t = i;
			while ((t % 5) == 0) {
				k++;
				t = t / 5;
			}
		}
		return k;
	}

	public static void main(String[] args) {
		TrailingZeroes t = new TrailingZeroes();
		int n = 100;
		System.out.println(t.trailingZeroes1(n));
		System.out.println(t.trailingZeroes(n));
	}

}
